package com.aier.proxy.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.service.IAdminVideoService;
import com.aier.common.dao.ICommonDAO;
import com.aier.entrance.entity.EntranceDevice;
import com.aier.entrance.service.IVideoDeviceService;
import com.aier.proxy.entity.VideoDeviceInfo;
import com.aier.proxy.service.IProxyService;
import com.aier.user.common.UserFinalPageSize;

@Scope("prototype")
@Component("proxyVideoAction")
public class ProxyVideoAction extends ProxyBaseAction {
    /**
     * 视频
     */
    private static final long serialVersionUID = 1L;
    
    @Resource(name = "videoDeviceService")
    private IVideoDeviceService videoDeviceService;
    
    @Resource(name = "adminVideoService")
    private IAdminVideoService adminVideoService;
    
    private List<VideoDeviceInfo> vds;
    
    private VideoDeviceInfo videoDevice;
    
    private List<EntranceDevice> entranceList;
    
    private Integer pid;
    
    //页数
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    //错误码
    private int s;
    
    //设备sn
    private String sn;
    //状态
    private Short state;
    //设备厂家
    private Short supplier;
    
    private Long vid;
    
    private String user;
    
    private String pwd;
    
    private Long entrance;
    
    // 排序方式
    private String sord;
    // 排序字段
    private String sort;
    
    @Override
    public String execute(){
        
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String showVideo(){
        if (page <= 0) {
            page = 1;
        }
        int sortable=-1;
        if("sn".equals(sort)){
            sortable = ("asc".equals(sord))?IProxyService.ENTRANCE_SORTABLE_SN:IProxyService.ENTRANCE_SORTABLE_SN_DESC;
        }
        Map<String, Object> map = null;
        map = videoDeviceService.searchProxyVideoInfo(page,UserFinalPageSize.USERIC_ICARD_PAGESIZE,pid,sn,state,supplier,sortable);
        vds = (List<VideoDeviceInfo>) map.get(ICommonDAO.OBJ_LIST);
        if (null == vds) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;

        return SUCCESS;
    }
    
    public String delVideo() {
        s = adminVideoService.updateVideoByid(vid);
        return SUCCESS;
    }
    
    public String showVideoDetail() {
        videoDevice = videoDeviceService.searchByvid(vid);
        entranceList = videoDeviceService.searchEntranceByUid(pid);
        return SUCCESS;
    }
    
    public String updateLoad() {
        s = videoDeviceService.updateVideoByvid(vid, state, user, pwd);
        if (s == 1) {
            if (entrance!=-1) {
                s = videoDeviceService.updateVideoEntrance(entrance, vid);
            }
        }
        
        return SUCCESS;
    }
    
    public String setGone() {
        s = videoDeviceService.updateVideoState(vid);
        return SUCCESS;
    }
    
    public void setVideoDeviceService(IVideoDeviceService videoDeviceService) {
        this.videoDeviceService = videoDeviceService;
    }
    
    public List<VideoDeviceInfo> getVds() {
        return vds;
    }

    public void setVds(List<VideoDeviceInfo> vds) {
        this.vds = vds;
    }
    
    public int getPage() {
        return page;
    }


    public void setPage(int page) {
        this.page = page;
    }


    public int getPage_size() {
        return page_size;
    }


    public int getPage_count() {
        return page_count;
    }


    public int getCount() {
        return count;
    }


    public int getS() {
        return s;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public void setSupplier(Short supplier) {
        this.supplier = supplier;
    }

    public void setVid(Long vid) {
        this.vid = vid;
    }
    
    public void setAdminVideoService(IAdminVideoService adminVideoService) {
        this.adminVideoService = adminVideoService;
    }

    public VideoDeviceInfo getVideoDevice() {
        return videoDevice;
    }

    public void setVideoDevice(VideoDeviceInfo videoDevice) {
        this.videoDevice = videoDevice;
    }

    public List<EntranceDevice> getEntranceList() {
        return entranceList;
    }

    public void setEntranceList(List<EntranceDevice> entranceList) {
        this.entranceList = entranceList;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public Long getEntrance() {
        return entrance;
    }

    public void setEntrance(Long entrance) {
        this.entrance = entrance;
    }
    
    public void setSord(String sord) {
        this.sord = sord;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }
    
    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

}
